package com.globallogic.jira.gadget.renderer;

import com.atlassian.jira.issue.Issue;

/**
 * Tree renderer for report
 * 
 * @author anton.pereverziev
 * 
 */
public class TreeRendererForReport extends AbstractTreeRenderer {

	@Override
	protected String getNodeContent(Issue issue) {

		StringBuilder content = new StringBuilder();

		content.append("<a href=\"/jira/browse/" + issue.getKey()
				+ "\" target=\"_parent\"> \n");
		content.append(getIssueKey(issue));
		content.append("</a> \n");
		content.append("<img src=\"/jira"
				+ issue.getPriorityObject().getIconUrl() + "\"/> \n");
		content.append("<img src=\"/jira"
				+ issue.getIssueTypeObject().getIconUrl() + "\"/> \n");
		content.append("<img src=\"/jira"
				+ issue.getStatusObject().getIconUrl() + "\"/> \n");
		content.append(issue.getSummary() + "\n");
		content.append("<b>Version(s): </b>" + getVersions(issue) + "\n");
		content.append("<b>Assignee: </b>" + issue.getAssigneeUser().getName()
				+ "\n");
		content.append("<b>Original estimate: </b>"
				+ timeConvert(issue.getOriginalEstimate()) + "\n");
		content.append("<b>Time spent: </b>"
				+ timeConvert(issue.getTimeSpent()) + "\n");

		return content.toString();
	}

	@Override
	public String getHTMLHead(String projectName, String issueType,
			String fixVersion, String linkType, String includeSubtasks) {

		StringBuilder result = new StringBuilder();
		// Project name
		result.append("<div style=\"text-align: center;\">");
		result.append("<span style=\"font-size: 18pt;\">Project: </span>");
		result.append("<span style=\"font-size: 20pt;color: blue;\">"
				+ projectName + "</span>");
		result.append("</div>");
		result.append("<br/>");
		// Filters
		result.append("<div style=\"text-align: center;\">");
		result.append("<span style=\"font-size: 14pt;\">Filters: &nbsp; </span>");
		result.append("<span style=\"font-size: 12pt;\">");
		result.append("Root issue type:<span style=\" color:green;\"> "
				+ issueType + "</span>, &nbsp;");
		result.append("LinkType: <span style=\" color:green;\">" + linkType
				+ "</span>, &nbsp;");
		result.append("Root issue fix version: <span style=\" color:green;\">"
				+ fixVersion + "</span>, &nbsp;");
		result.append("Include subtasks:<span style=\" color:green;\"> "
				+ includeSubtasks + " </span> &nbsp;");
		result.append("</span>");
		result.append("</div>");

		return result.toString();
	}

}
